package com.zhumr.web.controller;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhumr.model.Advice;
import com.zhumr.service.IAdviceService;

/**
 * 投诉建议
 * 
 * @author HP
 *
 */
@Controller
@RequestMapping("/webAdvice")
public class AdviceController {

	@Autowired
	private IAdviceService adviceService;

	/**
	 * 投诉与建议
	 * 
	 * @param request
	 * @param name
	 * @param qq
	 * @param phone
	 * @param title
	 * @param description
	 * @return
	 */
	@RequestMapping("/subAdvice")
	@ResponseBody
	public Map<String, Object> subAdvice(HttpServletRequest request, String name, String qq, String phone,
			String title, String description) throws IOException {

		Advice ad = new Advice();
		ad.setAddTime(new Date());
		ad.setDescription(description);
		ad.setName(name);
		ad.setPhone(phone);
		ad.setQq(qq);
		ad.setTitle(title);

		int result = adviceService.subAdvice(ad);
		Map<String, Object> resultMap = new HashMap<String, Object>();

		if (result > 0) {
			resultMap.put("code", "0");
		} else {
			resultMap.put("code", "1");
		}

		return resultMap;
	}

}
